package com.niiwoo.civet.trade.configuration;

import com.niiwoo.civet.trade.constant.listener.CreditMQConstant;
import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 授信MQ配置
 * Created by dell on 2018/4/19.
 * Description：civet-app
 */
@Configuration
public class CreditMqConfiguration {

    @Bean
    public Exchange creditAmountExchange(RabbitAdmin admin) {
        Exchange exchange = new DirectExchange(CreditMQConstant.Exchange.V515_CREDIT_AMOUNT_EXCHANGE, true, true);
        admin.declareExchange(exchange);
        return exchange;
    }

    @Bean
    public Queue creditAmountQueue(RabbitAdmin admin) {
        Queue queue = new Queue(CreditMQConstant.Queue.V515_GET_CREDIT_AMOUNT, true);
        admin.declareQueue(queue);
        return queue;
    }

    @Bean
    public Binding creditAmountBinding(RabbitAdmin admin) {
        Binding binding = BindingBuilder.bind(creditAmountQueue(admin))
                                        .to(creditAmountExchange(admin))
                                        .with(CreditMQConstant.getRoutingKey(CreditMQConstant.Exchange.V515_CREDIT_AMOUNT_EXCHANGE,CreditMQConstant.Queue.V515_GET_CREDIT_AMOUNT))
                                        .noargs();
        admin.declareBinding(binding);
        return binding;
    }
}
